﻿@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.Catalog.ProductTags").Text;
    //active menu item (system name)
    Html.SetActiveMenuItemSystemName("Product tags");
}

@using (Html.BeginForm(null, null, FormMethod.Post, new {id = "product-tags-form"}))
{
    @Html.AntiForgeryToken()
    <div class="content-header clearfix">
        <h1 class="pull-left">
            @T("Admin.Catalog.ProductTags")
        </h1>
        <div class="pull-right">
            &nbsp;
        </div>
    </div>

    <div class="content">
        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div id="product-tags-grid"></div>

                    <script>
                        $(document).ready(function() {
                            $("#product-tags-grid").kendoGrid({
                                dataSource: {
                                    type: "json",
                                    transport: {
                                        read: {
                                            url: "@Html.Raw(Url.Action("ProductTags", "Product"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: addAntiForgeryToken
                                        },
                                        destroy: {
                                            url: "@Html.Raw(Url.Action("ProductTagDelete", "Product"))",
                                            type: "POST",
                                            dataType: "json",
                                            data: addAntiForgeryToken
                                        }
                                    },
                                    schema: {
                                        data: "Data",
                                        total: "Total",
                                        errors: "Errors",
                                        model: {
                                            id: "Id",
                                            fields: {
                                                Name: { editable: true, type: "string" },
                                                Value: { editable: true, type: "string" },
                                                Store: { editable: true, type: "string" },
                                                StoreId: { editable: true, type: "number" },
                                                Id: { editable: false, type: "number" }
                                            }
                                        }
                                    },
                                    requestEnd: function(e) {
                                        if (e.type == "create" || e.type == "update") {
                                            this.read();
                                        }
                                    },
                                    error: function(e) {
                                        display_kendoui_grid_error(e);
                                        // Cancel the changes
                                        this.cancelChanges();
                                    },
                                    pageSize: @(defaultGridPageSize),
                                    serverPaging: true,
                                    serverFiltering: true,
                                    serverSorting: true
                                },
                                pageable: {
                                    refresh: true,
                                    pageSizes: [@(gridPageSizes)],
                                    @Html.Partial("_GridPagerMessages")
                                },
                                editable: {
                                    confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                    mode: "inline"
                                },
                                scrollable: false,
                                columns: [
                                {
                                    field: "Name",
                                    title: "@T("Admin.Catalog.ProductTags.Fields.Name")",
                                    width: 300
                                }, {
                                    field: "ProductCount",
                                    title: "@T("Admin.Catalog.ProductTags.Fields.ProductCount")",
                                    width: 150
                                }, {
                                    field: "Id",
                                    title: "@T("Admin.Common.Edit")",
                                    width: 150,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                    template: "<button onclick=\"javascript:OpenWindow('@Url.Content("~/Admin/Product/EditProductTag/")#=Id#?btnId=btnRefresh&formId=product-tags-form', 800, 320, true); return false;\" class='btn btn-default'><i class=\"fa fa-pencil\"></i>@T("Admin.Common.Edit")</button>"
                                }, {
                                    command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                    title: "@T("Admin.Common.Delete")",
                                        width: 100
                                    }
                                ]
                            });
                        });
                    </script>
                    <input type="submit" id="btnRefresh" style="display: none"/>
                    <script type="text/javascript">
                        $(document).ready(function() {
                            $('#btnRefresh').click(function() {
                                //refresh grid
                                var grid = $("#product-tags-grid").data('kendoGrid');
                                grid.dataSource.read();

                                //return false to don't reload a page
                                return false;
                            });
                        });
                    </script>
                </div>
            </div>
        </div>
    </div>
}